home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / appsrcs.zip / APPTASK.ZIP / APPCLOSE.C next >
C/C++ Source or Header  |  1993-02-13  |  2KB  |  71 lines

  1. #define STRICT
  2. #include <windows.h>
  3. #include <windowsx.h>
  4. #include <shellapi.h>
  5. #include <string.h>
  6. #include "apptask.h"
  7.  
  8. BOOL fWMCloseSeen = TRUE;
  9. FARPROC lpfnOrgCloseWndProc;
  10.  
  11. long WINAPI WaitForWMCloseWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  12.     {
  13.     LONG    lRet;
  14.  
  15.     lRet = CallWindowProc(lpfnOrgCloseWndProc, hWnd, message, wParam, lParam);
  16.     if(message == WM_CLOSE)
  17.     {
  18.     if(IsWindow (hWnd))
  19.         SetWindowLong(hWnd, GWL_WNDPROC, (DWORD) lpfnOrgCloseWndProc);
  20.         fWMCloseSeen = TRUE;
  21.     }
  22.     return lRet;
  23.     }
  24.  
  25. /*------------------------------------------------------------------------*/
  26. VOID PASCAL WaitForWMClose(HWND hWndClose)
  27.     {
  28.     static FARPROC  lpfnMy = NULL;
  29.     MSG msg;
  30.  
  31.     if(lpfnMy == NULL)
  32.     {
  33.     lpfnMy = MakeProcInstance((FARPROC) WaitForWMCloseWndProc, hInst);
  34.         if (lpfnMy == NULL)
  35.             return;
  36.     }
  37.     lpfnOrgCloseWndProc = (FARPROC) GetWindowLong(hWndClose, GWL_WNDPROC);
  38.     SetWindowLong(hWndClose, GWL_WNDPROC, (DWORD) lpfnMy);
  39.     fWMCloseSeen = FALSE;
  40.  
  41.     //  This is a MUST here. We need to keep messages flowing around while
  42.     //  we're waiting a program to make up his mind with this close thing.
  43.     do    {
  44.     if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  45.         {
  46.         TranslateMessage(&msg);
  47.         DispatchMessage(&msg);
  48.         }
  49.     }
  50.     while(!fWMCloseSeen);
  51.  
  52.     // We've just seen WM_DESTROY let the app to clean up
  53.     // himself completely before we go on.
  54.     Yield();
  55.     }
  56.  
  57. /*-------------------------------------------------------------------------*/
  58. BOOL PASCAL CloseApp(HWND hWndClose)
  59.     {
  60.     if(!IsDosWindow(hWndClose))
  61.     {
  62.     PostMessage(hWndClose, WM_CLOSE, 0, 0L);
  63.     WaitForWMClose(hWndClose);
  64.     //if windows is still there, application refused to die.
  65.     if(IsWindow(hWndClose))
  66.         return FALSE;
  67.     return TRUE;
  68.     }
  69.     return FALSE;
  70.     }
  71.